﻿Imports MySql.Data.MySqlClient

Public Class add1_2_1

    Public SQL As MySqlConnection
    Public selectedEmployee As String
    Public respone As Object

    Public Sub New(ByRef SQLConnection As MySqlConnection, ByRef inEmployee As String)
        InitializeComponent()
        SQL = SQLConnection
        selectedEmployee = inEmployee
    End Sub

    ' Private Sub add1_2_1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    'Dim mainForm As main = New main()
    '   mainForm.Show()
    'Me.Close()
    'End Sub

    Private Sub add1_2_1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox4.Text = "00.00"
        TextBox5.Text = "0"
    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim mySqlCommand As New MySqlCommand

        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
            MsgBox("Please complete all field", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Warning Message")
        Else
            respone = MsgBox("Are you sure to save data", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
            If respone = 1 Then
                If SQL.State = ConnectionState.Closed Then
                    SQL.Open()
                End If

                Try
                    mySqlCommand.CommandText = "INSERT INTO Course (course_name,course_start_date,course_cost,course_trainer,course_duration) VALUES ('" & TextBox1.Text & "','" & DateTimePicker1.Value.Year.ToString() & "-" & DateTimePicker1.Value.Month.ToString() & "-" & DateTimePicker1.Value.Day.ToString() & "', " & TextBox5.Text & ", '" & TextBox2.Text & "'," & TextBox4.Text & ");"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = SQL

                    mySqlCommand.ExecuteNonQuery()

                Catch ex As Exception

                    MsgBox("Please check your data again!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Warning Message")
                    Exit Sub

                End Try



                SQL.Close()


                '=========================================

                Dim mainForm As add1_2 = New add1_2(SQL, selectedEmployee)
                mainForm.Show()

                Me.Close()


            End If
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

    End Sub


    Private Sub BackButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackButton.Click
        Dim mainForm As add1_2 = New add1_2(SQL, selectedEmployee)
        mainForm.Show()

        Me.Close()
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

    End Sub
End Class